package cn.i7baozh.cloud.payment.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.i7baozh.cloud.api.dto.PayDTO;
import cn.i7baozh.cloud.api.dto.ReturnResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author zhangbaoqi532
 * @date 2024/12/26
 */
@RestController
@Slf4j
public class PayCircuitBreakerController {

    @GetMapping("/provider/circuitBreaker/{id}")
    public ReturnResponse<String> get(@PathVariable(value = "id") Integer id) {
        //feign 重试机制
        if (id < 0) {
            //模拟报错
            throw new RuntimeException("不存在啊，查什么查");
        }
        if (id == 100) {
            try{
                //模拟超时
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                log.error("Error,", e);
            }
        }
        return ReturnResponse.success("请求成功了，id: " + id + " ,uuid : "  + UUID.fastUUID().toString(true));
    }
}
